<template>
  <div>
    <!-- <h3>list组件</h3> -->
    <!-- row-key一行的唯一标识 default-expand-all默认展开所有 -->
    <el-table
      :data="list"
      style="width: 100%"
      row-key="id"
      border
      :tree-props="{ children: 'children' }"
    >
      <el-table-column prop="id" label="规格编号"> </el-table-column>
      <el-table-column prop="specsname" label="规格名称"> </el-table-column>
      <el-table-column label="规格属性">
        <template slot-scope="scope">
          <el-tag v-for="(item,index) in scope.row.attrs" :key="index">{{item}}</el-tag>
        </template>
      </el-table-column>

      <el-table-column label="状态">
        <template slot-scope="scope">
          <el-button type="primary" v-if="scope.row.status == 1"
            >启用</el-button
          >
          <el-button type="info" v-else>禁用</el-button>
        </template>
      </el-table-column>

      <el-table-column prop="address" label="操作">
        <template slot-scope="scope">
          <el-button type="primary" @click="handleEdit(scope)">编辑</el-button>
          <!-- <el-button type="danger" @click="handleDelete(scope)">删除</el-button> -->
          <del-btn @confirm="del(scope)"></del-btn>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template> 

<script>
import { reqspecsdelete } from "../../../http/api";
import { successAlert } from "../../../utils/alert";
import { mapActions, mapGetters } from "vuex";
export default {
  data() {
    return {};
  },

  methods: {
    ...mapActions({
      reqList: "specs/reqList",
    }),

    handleEdit(scoped) {
      console.log(scoped.row);
      // scoped.$index下标
      // scoped.row那条数据
      this.$emit("willUpdate", scoped.row.id);
    },
    
    del(scope) {
      reqspecsdelete({
        id: scope.row.id,
      }).then((res) => {
        if (res.data.code == 200) {
          successAlert(res.data.msg);
          // 重新渲染列表
          this.reqList();
        }
      });
    },
  },
  computed: {
    ...mapGetters({
      list: "specs/list",
    }),
  },
  mounted() {
    // 进来页面就触发
    this.reqList();
  },
};
</script>

<style scoped lang="less">
@import "../../../less/index.less";
img {
  width: 50px;
  height: 50px;
}
</style>